"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = Example2;

var _design = require("@discuzq/design");

var _react = _interopRequireDefault(require("react"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var imghtml = "\n<img width='200' height='200' src=\"https://main.qcloudimg.com/raw/9c701525249863334dbd86397b49a11d.jpg\" alt=\"\u56FE\u7247\" />\n";
var errorImgHtml = '<img width="200" height="200" src="https://23333.jpg" alt="图片" />';

function Example2() {
  var _React$useState = _react.default.useState(''),
      _React$useState2 = _slicedToArray(_React$useState, 2),
      renderContent = _React$useState2[0],
      setRenderContent = _React$useState2[1];

  var _React$useState3 = _react.default.useState(''),
      _React$useState4 = _slicedToArray(_React$useState3, 2),
      message = _React$useState4[0],
      setMessage = _React$useState4[1];

  var imgLoad = function imgLoad() {
    setRenderContent(imghtml);
  };

  var errorImgLoad = function errorImgLoad() {
    setRenderContent(errorImgHtml);
  };

  return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_design.RichText, {
    style: {
      width: 200,
      height: 200,
      border: '1px solid #000'
    },
    onImgsLoaded: function onImgsLoaded(e) {
      console.log(e);
      setMessage('图片加载完成');
    },
    onImgsErrored: function onImgsErrored(e) {
      console.log(e);
      setMessage('图片加载失败');
    },
    onImgClick: function onImgClick(e) {
      console.log(e);
      setMessage('图片点击');
    },
    onParse: function onParse(nodeTree, imgUrls) {
      console.log(nodeTree, imgUrls);
      setMessage('html解析完成');
    },
    content: renderContent
  }), /*#__PURE__*/_react.default.createElement("h3", {
    style: {
      margin: '20px 0'
    }
  }, "\u5F53\u524D\u4E8B\u4EF6\u72B6\u6001\uFF1A", message), /*#__PURE__*/_react.default.createElement(_design.Button, {
    type: "primary",
    onClick: imgLoad
  }, "\u52A0\u8F7D\u6B63\u5E38\u56FE\u7247"), /*#__PURE__*/_react.default.createElement(_design.Button, {
    type: "primary",
    onClick: errorImgLoad
  }, "\u52A0\u8F7D\u9519\u8BEF\u56FE\u7247"));
}